package cn.kgc.vue.service.impl;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.common.ResponseStatus;
import cn.kgc.vue.form.LogLsitForm;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.LogInfo;
import cn.kgc.vue.service.LogInfoService;
import cn.kgc.vue.mapper.LogInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author 
* @description 针对表【log_info】的数据库操作Service实现
* @createDate 2023-08-20 18:34:48
*/
@Service
public class LogInfoServiceImpl extends ServiceImpl<LogInfoMapper, LogInfo>
    implements LogInfoService{
    @Autowired
    private LogInfoMapper logInfoMapper;

    @Override
    public ResponseResult getlist(LogLsitForm logLsitForm) {
        ResponseResult responseResult = new ResponseResult();
        Page<LogInfo> page = new Page<>(logLsitForm.getPage(), logLsitForm.getLimit());
        LambdaQueryWrapper<LogInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(logLsitForm.getUsername()),LogInfo::getUsername,logLsitForm.getUsername()).orderByDesc(LogInfo::getId);
        Page<LogInfo> logInfoPage = logInfoMapper.selectPage(page, wrapper);
        List<LogInfo> records = logInfoPage.getRecords();
        long total = logInfoPage.getTotal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("log",records);
        responseResult.success(ResponseStatus.SUCCESS,map);
        return  responseResult;
    }
}




